<?php

namespace app\admin\controller\business;

use app\common\controller\Backend;

class Record extends Backend
{
    protected $model = null;
    //关联查询的意思
    protected $relationSearch = true;
    public function __construct()
    {
        parent::__construct();
        $this->model = model("Business.Record");
    }
    public function index($ids = NULL)
    {
        // $result=$this->model->with(['business'])->select();
        // halt(collection($result)->toArray());
        // exit;
        // var_dump($ids);
        if ($ids == null) {
            if ($this->request->isAjax()) {
                //接收参数
                list($where, $sort, $order, $offset, $limit) = $this->buildparams();

                $total = $this->model
                    ->with(['business'])
                    ->where($where)
                    ->order($sort, $order)
                    ->count();

                $list = $this->model
                    ->with(['business'])
                    ->where($where)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();
               
                //返回json数据
                $result = ['total' => $total, 'rows' => $list];

                return json($result);
                // echo json_encode($result);
            }
        } else {
            if ($this->request->isAjax()) {
                //接收参数
                list($where, $sort, $order, $offset, $limit) = $this->buildparams();

                $total = $this->model
                    ->with(['business'])
                    ->where($where)
                    ->where('busid', $ids)
                    ->order($sort, $order)
                    ->count();

                $list = $this->model
                    ->with(['business'])
                    ->where($where)
                    ->where('busid', $ids)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();

                //返回json数据
                $result = ['total' => $total, 'rows' => $list];

                return json($result);
            }
        }
        return $this->view->fetch();
    }
}